"use strict";
cc._RF.push(module, '9bd3er644pCxK+3aubWI7ZL', 'HuoChaiBang');
// scripts/huochai/HuoChaiBang.js

"use strict";

cc.Class({
    extends: cc.Component,

    properties: {
        startx: "int",
        starty: "int",
        otherHuoChai: cc.node
    },

    // use this for initialization
    onLoad: function onLoad() {

        cc.director.getCollisionManager().enabled = true;
        //cc.director.getCollisionManager().enabledDebugDraw = true;
        //cc.director.getCollisionManager().enabledDrawBoundingBox = true;

        this.startx = this.node.x;
        this.starty = this.node.y;

        this.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
            //this.opacity = 255;
            if (this.opacity == 255) {
                var delta = event.touch.getDelta();
                this.x += delta.x;
                this.y += delta.y;
            }
        }, this.node);

        this.node.on(cc.Node.EventType.TOUCH_END, function (event) {

            this.node.x = this.startx;
            this.node.y = this.starty;

            if (this.otherHuoChai != null) {
                if (this.node.opacity = 255 && this.otherHuoChai.node.opacity == 0) {
                    this.node.opacity = 0;
                    this.otherHuoChai.node.opacity = 255;
                } else {
                    this.node.opacity = 255;
                }
            }
        }, this);
    },

    onCollisionEnter: function onCollisionEnter(other) {
        //this.node.color = cc.Color.RED;
        // console.log('onCollisionEnter============'+this.name);
        this.otherHuoChai = other;
    },

    onCollisionStay: function onCollisionStay(other) {
        //console.log('on collision stay');
        this.otherHuoChai = other;
    },

    onCollisionExit: function onCollisionExit() {
        //this.node.color = cc.Color.WHITE;
        this.otherHuoChai = null;
    },

    // called every frame
    update: function update(dt) {}
});

cc._RF.pop();